package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.renwei.yunlong.R;
import com.zyf.fwms.commonlibrary.utils.AutoUtils;

/**
 * 技术专长--网络相关  Adapter  (废弃)
 *
 * Created by Administrator on 2017/8/25.
 */

public class ExpertiseInternetAdapter extends RecyclerView.Adapter<ExpertiseInternetAdapter.ExpertiseInternetViewHolder>{


    private LayoutInflater inflater;
    private Context context;
    //private String[] content = {"光端机","财务系统","项目管理系统","监视器","绩效考核系统","摄像机","人力资源管理","矩阵测试"};
    private String[] content = {"测试服务器","防火墙"};

    private int selectedPosition = -1;//记录

    private OnItemClickListener mOnItemClickListener;
    private ExpertiseInternetOnClickListener onClickListener;

    public ExpertiseInternetAdapter(Context context,ExpertiseInternetOnClickListener onClickListener){
        this.context =context;
        inflater = LayoutInflater.from(context);
        this.onClickListener = onClickListener;
    }

    @Override
    public ExpertiseInternetViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_expertise,null);
        AutoUtils.auto(view);
        return new ExpertiseInternetViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ExpertiseInternetViewHolder holder, final int position) {
        holder.btnItem.setText(content[position]);
        if (selectedPosition != -1){
            if (selectedPosition == position){
                //选中
                holder.btnItem.setBackgroundResource(R.drawable.button_expertise_card_pre);
                holder.btnItem.setTextColor(context.getResources().getColor(R.color.white));

            }else {
                holder.btnItem.setBackgroundResource(R.drawable.button_expertise_card_nor);
                holder.btnItem.setTextColor(context.getResources().getColor(R.color.text_black_color));
            }
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClickListener.setOnClickListener(content[position]);
                int pos = holder.getLayoutPosition();
                mOnItemClickListener.onItemClick(holder.itemView,pos,content[pos]);
            }
        });
    }

    public void setSelection(int position) {
        selectedPosition = position;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface ExpertiseInternetOnClickListener{
        void setOnClickListener(String content);
    }

    public interface OnItemClickListener{
        void onItemClick(View view,int position,String s);
    }

    @Override
    public int getItemCount() {
        return content.length;
    }

    static class ExpertiseInternetViewHolder extends RecyclerView.ViewHolder{
        private View itemView;
        private Button btnItem;

        public ExpertiseInternetViewHolder(View view) {
            super(view);
            itemView = view;
            btnItem = (Button) itemView.findViewById(R.id.btn_item);
        }
    }
}
